package com.zero.yygh.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zero.yygh.common.result.Result;
import com.zero.yygh.model.user.UserInfo;
import com.zero.yygh.user.service.UserInfoService;
import com.zero.yygh.vo.user.UserInfoQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author zero
 * @desc 用户管理
 * @create 2021/4/18
 */
@Api("用户管理API")
@RestController
@RequestMapping("/admin/user")
public class UserController {

    @Resource
    private UserInfoService userInfoService;

    @ApiOperation("分页条件查询用户列表")
    @GetMapping("{page}/{limit}")
    public Result<IPage<UserInfo>> list(@PathVariable Integer page, @PathVariable Integer limit, UserInfoQueryVo userInfoQueryVo){
        Page<UserInfo> pageParams = new Page<>(page, limit);
        return Result.ok(userInfoService.selectPage(pageParams, userInfoQueryVo));
    }

    @ApiOperation(value = "锁定")
    @GetMapping("lock/{userId}/{status}")
    public Result<Object> lock(@PathVariable("userId") Long userId, @PathVariable("status") Integer status){
        userInfoService.lock(userId, status);
        return Result.ok();
    }

    @ApiOperation("用户详情")
    @GetMapping("show/{userId}")
    public Result<Map<String, Object>> show(@PathVariable Long userId) {
        Map<String,Object> map = userInfoService.show(userId);
        return Result.ok(map);
    }

    @ApiOperation("认证审批")
    @GetMapping("approval/{userId}/{authStatus}")
    public Result<Object> approval(@PathVariable Long userId,@PathVariable Integer authStatus) {
        userInfoService.approval(userId,authStatus);
        return Result.ok();
    }



}
